package com.jintian.smart.kernel.security.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.jintian.smart.base.api.security.form.LoginLogQueryForm;
import com.jintian.smart.base.api.security.view.LoginLogVO;
import com.jintian.smart.kernel.common.controller.SupportBaseController;
import com.jintian.smart.kernel.common.context.ContextHolder;
import com.jintian.smart.kernel.core.constant.SwaggerTagConst;
import com.jintian.smart.kernel.core.domain.RequestUser;
import com.jintian.smart.kernel.core.domain.ResponseDTO;
import com.jintian.smart.kernel.security.service.LoginLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.beetl.sql.core.page.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录日志
 */
@RestController
@Tag(name = SwaggerTagConst.Support.LOGIN_LOG)
@RequestMapping("/sec/loginLog")
public class LoginLogController extends SupportBaseController {
    @Resource
    private LoginLogService loginLogService;

    @Operation(summary = "分页查询")
    @PostMapping("/page/query")
    @SaCheckPermission("support:loginLog:query")
    public ResponseDTO<PageResult<LoginLogVO>> queryByPage(@RequestBody LoginLogQueryForm queryForm) {
        return loginLogService.queryByPage(queryForm);
    }

    @Operation(summary = "分页查询当前登录人信息")
    @PostMapping("/page/query/login")
    public ResponseDTO<PageResult<LoginLogVO>> queryByPageLogin(@RequestBody LoginLogQueryForm queryForm) {
        RequestUser requestUser = ContextHolder.getUser();
        queryForm.setUserId(requestUser.getUserId());
        queryForm.setUserType(requestUser.getUserType().getValue());
        return loginLogService.queryByPage(queryForm);
    }
}
